package com.example.homecunter.video.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.common.utils.OnItemClickListener;
import com.example.homecunter.R;
import com.example.homecunter.video.entity.ChannelEntity;

import java.util.List;

public class ChannelAdapter extends RecyclerView.Adapter<ChannelAdapter.ChannelViewHodel> {
    Context context;
    List<ChannelEntity> data;

    LayoutInflater layoutInflater;

    OnItemClickListener onItemClickListener;
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public ChannelAdapter(Context context, List<ChannelEntity> data) {
        this.context = context;
        this.data = data;
        layoutInflater = LayoutInflater.from(context);////
    }


    @NonNull
    @Override
    public ChannelViewHodel onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ChannelViewHodel(layoutInflater.inflate(R.layout.item_type,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull ChannelAdapter.ChannelViewHodel holder, int position) {
        holder.textView.setText(data.get(position).getChannelname());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i("--a", "onClick: "+data.get(position).getChannelname());
                onItemClickListener.onItemClick(position);


            }
        });

    }


    @Override
    public int getItemCount() {
        return data.size();
    }


    public class ChannelViewHodel extends RecyclerView.ViewHolder {
        TextView textView;
        public ChannelViewHodel(@NonNull View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.item_type_tv);
        }
    }

}
